import 'package:flutter/material.dart';

import 'data/home/home_screen.dart';


void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    /*单类型数据
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: const Text('HTTP Demo')),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              ElevatedButton(
                onPressed: _fetchUsers,
                child: Text("GET Users"),
              ),
              ElevatedButton(
                onPressed: _createUser,
                child: Text("POST Users"),
              ),
              const SizedBox(height: 20),
              ElevatedButton(
                onPressed: () => _createPost,
                child: const Text('POST Data'),
              ),
              // 添加结果显示区域
              _buildResultDisplay(),
            ],
          ),
        ),
      ),
    );*/
    return MaterialApp(
      title: '多类型数据示例',
      theme: ThemeData(
        primarySwatch: Colors.lightBlue,
        useMaterial3: true,
      ),
      home:const HomeScreen(),
      debugShowCheckedModeBanner: false,
      /*home: DefaultTabController(
        length: 3,
        child: Scaffold(
          appBar: AppBar(
            bottom: const TabBar(
              tabs: [
                Tab(icon: Icon(Icons.people), text: '用户'),
                Tab(icon: Icon(Icons.shopping_cart), text: '产品'),
                Tab(icon: Icon(Icons.receipt), text: '订单'),
              ],
            ),
          ),
          body: TabBarView(
            children: [
              UserTab(userRepo: _userRepo),
              ProductTab(productRepo: _productRepo),
              OrderTab(userId: "123", repository: _orderRepo),
            ],
          ),
        ),
      ),*/
    );
  }

/*void _fetchUsers() async {
    final response = await _userRepo.fetchUsers();
    if (response.data != null) {
      print("Users: ${response.data![0].name}"); // 打印第一个用户名
    } else {
      print("Error: ${response.message}");
    }
  }*/

/*void _createUser() async {
    final newUser = User(id: 101, name: "John Doe", email: "john@example.com");
    final response = await _userRepo.addUser(newUser);
    if (response.data != null) {
      print("Created user: ${response.data!.email}");
    } else {
      print("Error: ${response.message}");
    }
  }


  Widget _buildResultDisplay() {
    return FutureBuilder(
      future: null, // 初始为空
      builder: (context, snapshot) {
        if (snapshot.connectionState == ConnectionState.waiting) {
          return const CircularProgressIndicator();
        } else if (snapshot.hasError) {
          return Text('Error: ${snapshot.error}',
              style: const TextStyle(color: Colors.red));
        } else if (snapshot.hasData) {
          final result = snapshot.data as ApiResponse;
          if (result.data is List<User>) {
            final users = result.data as List<User>;
            return Text('Fetched ${users.length} users');
          } else if (result.data is User) {
            final user = result.data as User;
            return Text('Created user: ${user.name} (ID: ${user.id})');
          } else if (result.data is Post) {
            final post = result.data as Post;
            return Text('Created post: ${post.title} (ID: ${post.id})');
          } else {
            return Text('Result: ${result.message}');
          }
        } else {
          return const Text('Click a button to start');
        }
      },
    );
  }*/
}
